package lab03.test03;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;

public class Writer {
    public static void main(String[] args) {
        String path = "D:\\旅院\\作业\\java\\2.txt"; //定义一个路径
        BufferedWriter writer = null;  //writer开始为空

        try {
            writer = new BufferedWriter(new FileWriter(path)); //路径指向

            writer.write("Beijing 欢迎你！");
            writer.newLine();//换行

        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                writer.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }


        //追加
        FileWriter file = null;
        try {
            file = new FileWriter("D:\\旅院\\作业\\java\\2.txt", true);
            file.write("我的学号是：你自己的学号");
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                file.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }
}
